# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=persistent-sqlite
pkgname=haskell-persistent-sqlite
pkgver=2.13.1.0
pkgrel=62
pkgdesc="Backend for the persistent library using sqlite3"
url="https://www.yesodweb.com/book/persistent"
license=("MIT")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'sqlite' 'haskell-aeson' 'haskell-conduit' 'haskell-microlens-th'
         'haskell-monad-logger' 'haskell-persistent' 'haskell-resource-pool' 'haskell-resourcet'
         'haskell-unliftio-core' 'haskell-unordered-containers')
makedepends=('ghc' 'haskell-fast-logger' 'haskell-hspec' 'haskell-hunit' 'haskell-microlens'
             'haskell-persistent-test' 'haskell-quickcheck' 'haskell-system-fileio'
             'haskell-system-filepath' 'haskell-temporary')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('19842dcd867f57ac2f81d8651838f41f6a4f0074293c0b3a21a52d2fb96410c26d5340307983da21ca89170a01621da257320e36f33170657acb6890f70299d4')

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
            -f-build-sanity-exe -fsystemlib -fuse-pkgconfig
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
